package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.comon.ResultInfo;
import com.itheima.reggie.domain.Orders;
import com.itheima.reggie.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrdersService ordersService;

    //提交订单
    @PostMapping("/submit")
    public ResultInfo<Object> saveOrder(@RequestBody Orders orders) {
        ordersService.saveOrder(orders);
        return ResultInfo.success(null);
    }

    //查询订单
    @GetMapping("/userPage")
    public ResultInfo<Page<Orders>> findOrders(@RequestParam(defaultValue = "1") Integer page,
                                               @RequestParam(defaultValue = "5") Integer pageSize) {
        Page<Orders> ordersPage = ordersService.findOrders(page, pageSize);
        return ResultInfo.success(ordersPage);
    }
}
